package com.ptszyxx.popose.module.main.mine;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProviders;

import com.ptszyxx.popose.BR;
import com.ptszyxx.popose.R;
import com.ptszyxx.popose.common.constants.BundleConstant;
import com.ptszyxx.popose.common.enums.MineFollowTabEnum;
import com.ptszyxx.popose.databinding.FragmentMineFollowBinding;
import com.ptszyxx.popose.module.main.mine.vm.MineFollowVM;
import com.ysg.base.BaseFragment;
import com.ysg.http.data.AppViewModelFactory;

import java.util.ArrayList;
import java.util.List;

public class MineFollowFragment extends BaseFragment<FragmentMineFollowBinding, MineFollowVM> {
    private String[] mTitles;
    private MineFollowTabEnum tabEnum;

    @Override
    public int initContentView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return R.layout.fragment_mine_follow;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }

    @Override
    public MineFollowVM initViewModel() {
        AppViewModelFactory factory = AppViewModelFactory.getInstance(getActivity().getApplication());
        return ViewModelProviders.of(this, factory).get(MineFollowVM.class);
    }

    @Override
    public void initView() {
        super.initView();
        mTitles = getResources().getStringArray(R.array.mine_follow_tab);
        binding.tabLayout.initGrid(this, binding.viewPager, mTitles,  getFragments());

        switch (tabEnum){
            case follow:
                binding.viewPager.setCurrentItem(0);
                break;
            case fans:
                binding.viewPager.setCurrentItem(1);
                break;
        }
    }

    @Override
    public void initParam() {
        super.initParam();
        Bundle bundle = getArguments();
        if(bundle != null){
            String tab = bundle.getString(BundleConstant.TAB);
            tabEnum = MineFollowTabEnum.get(tab);
        }
    }

    public List<Fragment> getFragments(){
        List<Fragment> fragments = new ArrayList<>();
//        fragments.add(new MineFollowTabFragment(MineFollowTabEnum.intimacy));
        fragments.add(new MineFollowTabFragment(MineFollowTabEnum.follow));
        fragments.add(new MineFollowTabFragment(MineFollowTabEnum.fans));
        return fragments;
    }
}
